
__author__="Action Farsi"
__date__ ="$22-giu-2009 22.46.17$"

from logger import logging

class Ability:
    """ There are passive and active ability.
    Each ability can work with the item of the slot
    
    Active - close range
    """
    def __init__(self, name = "", prereq = (0,0,0,0,0,0)):
        if name:
            self.name = name
        self.prerequisites = prereq
        #self.actions = []
        self.type = set()
        self.kind = "close"

    def use_mex(self):
        return "%s used"%self.name

    def attack(self):
        pass

    def set_attack(ab, dam_mod = 2, att_bonus = (0,0,0,0,0,0)):
        ab.type.add("weapon")
        ab.dam_mod = dam_mod
        ab.att_bonus = att_bonus

    def set_defence(ab, def_mod = 2, def_bonus = (0,0,0,0,0,0)):
        ab.type.add("defence")
        ab.def_mod = def_mod
        ab.def_bonus = def_bonus

    def set_combat_skill(ab, kind, att_skill, def_skill):
        ab.kind = kind
        ab.att_skill = att_skill
        ab.def_skill = def_skill

    def __str__(self):
        return self.name

    def add_type(self, type):
        while type != 'root':
            self.type.add(type)
            type = Slot.slot_tree[type]
    
def add_slot_type(type, slot = None):
    if slot is None:
        slot = set()
    while type != 'root':
        slot.add(type)
        type = Slot.slot_tree[type]
    return slot

class Slot:
    slot_tree = {'body': 'root',
           'hand': 'body',
           'r-hand': 'hand',
           'l-hand': 'hand',
           'attack': 'root',
           'close': 'attack',
           'range': 'attack',
           'item': 'root',
           'weapon': 'hand',
           'defence': 'root',
           'special': 'root',
           'cape': 'defence'}


    def __init__(self, slot_type, name = "Ability Slot"):
        self.name = name
        self.type = add_slot_type(slot_type)
        self.ability = Ability("None")
        self.item = None


    def set_ability(self, ability):
        if ability.type <= self.type:
            self.ability = ability
            logging.debug("Setting %s in %s"%(ability.name,self.name))
            return True
        return False

    def put_item(self, item):
        if item.type < self.type:
            self.item = item
            return True
        return False
 
 

iron_fist = Ability("Iron Fist")
Ability.set_attack(iron_fist,30, att_bonus = (0.1,0,0,0,0,0))

iron_skin = Ability("Iron Skin")
Ability.set_defence(iron_skin,2, def_bonus = (0,0.3,0,0,0,0))

kungfu = Ability("Kung Fu")
Ability.set_combat_skill(kungfu,"close", att_skill = (1,0,0,0,0,1), def_skill = (0,1,0,0,0,1))
kungfu.type.add("close")

streetfight = Ability("Street Fight")
Ability.set_combat_skill(streetfight,"close", att_skill = (1,0,0,1,0,0), def_skill = (0,1,0,0,0.8,0))

toughness = Ability("Toughness")
Ability.set_defence(iron_skin, 0 , def_bonus = (0,0.4,0,0,0,0))

sharpshooter = Ability("Shooter")
Ability.set_combat_skill(sharpshooter,"range",  att_skill = (0,0,0,2,0,0), def_skill = (0,1,0,0,0,1))


abilities = {}
for i in [iron_fist, iron_skin, kungfu, streetfight, toughness, sharpshooter]:
    abilities[i.name] = i

slots = {"combat_style": Slot("close", name = "Combat Style"),
        "fire_ability": Slot("range", name = "Firing Ability"),
        "right_hand" : Slot("weapon", name = "Right Hand"),
        "defence" : Slot("defence", name = "Defence"),
        "special" : Slot("weapon", name = "Special"),
        }

## Ability tree
## body hand r-hand l-hand
## mind
## attack close range
print slots['fire_ability'].type


if __name__ == "__main__":
    print "Hello";